package com.app.shop.controller.api;

import com.alibaba.fastjson.JSONObject;
import com.app.shop.controller.system.BaseController;
import com.app.shop.entity.WgOrder;
import com.app.shop.entity.query.WgOrderQuery;
import com.app.shop.entity.show.BaseShow;
import com.app.shop.entity.show.WgOrderShow;
import com.app.shop.service.shop.WgOrderService;
import com.app.shop.util.ApiRest;
import com.app.shop.util.ClassUtil;
import com.app.shop.util.Constant;
import com.github.pagehelper.Page;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;


/**
 * 订单服务类Controller
 *
 * @author  chen li wei
 * @version 21:14 2019-5-10
 */
@Controller
@RequestMapping(value = "/wgOrder")
public class WgOrderController extends BaseController {

    private static final Logger log = LoggerFactory.getLogger(WgOrderController.class);
    @Autowired
    WgOrderService sysOrderService;

    /**
     * 查询订单列表
     * @param sysOrderQuery 查询订单参数
     * @return 返回订单列表
     * @throws IOException
     */
    @ResponseBody
    @RequestMapping(value = "/getOrderList")
    public ApiRest getDictList(@RequestBody WgOrderQuery sysOrderQuery) {
        log.debug(JSONObject.toJSON(sysOrderQuery).toString());
        //查询
        Page<WgOrder> sysOrderList=sysOrderService.getWgOrderList(sysOrderQuery);
        //查询结果对象置换
        List<WgOrderShow> resList=new ArrayList<WgOrderShow>();
        WgOrderShow sysOrderShow;
        //数据转换
        for(WgOrder sysOrder:sysOrderList){
            sysOrderShow=new WgOrderShow();
            try {
                ClassUtil.fatherToChild(sysOrder,sysOrderShow);
            } catch (Exception e) {
                e.printStackTrace();
            }
            //码表值补全
            sysOrderShow.dataSet();
            resList.add(sysOrderShow);
        }
        return new ApiRest(Constant.REST_SUCCESS_CODE, Constant.SUCCESS_MESSAGE,
                new BaseShow(sysOrderList.getPageNum(), sysOrderList.getPageSize(), sysOrderList.getTotal(), sysOrderList.getPages(), resList));
    }

    //修改订单为已完成状态

    //查看订单详情


}
